﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using FarmacieDAL;

namespace Farmacie.Controls
{
    /// <summary>
    /// Interaction logic for RaportVanzari.xaml
    /// </summary>
    public partial class RaportVanzari : UserControl, INotifyPropertyChanged
    {
        private DateTime dataInceput;
        private DateTime dataSfarsit;

        public DateTime DataInceput
        {
            get { return dataInceput; }
            set
            {
                if (value != dataInceput)
                {
                    dataInceput = value;
                    OnPropertyChanged("DataInceput");
                }
            }
        }

        public DateTime DataSfarsit
        {
            get { return dataSfarsit; }
            set
            {
                if (value != dataSfarsit)
                {
                    dataSfarsit = value;
                    OnPropertyChanged("DataSfarsit");
                }
            }
        }

        private List<TotalChitanta> totaluriChitante;

        public List<TotalChitanta> TotaluriChitante
        {
            get { return totaluriChitante; }
            set
            {
                if (value != totaluriChitante)
                {
                    totaluriChitante = value;
                    OnPropertyChanged("TotaluriChitante");
                }
            }
        }

        public RaportVanzari()
        {
            InitializeComponent();
            this.DataContext = this;
            buttonGenereaza.Click += new RoutedEventHandler(buttonGenereaza_Click);
            DataInceput = DateTime.Now;
            DataSfarsit = DateTime.Now;
        }

        public void RefreshControl()
        {
            DataInceput = DateTime.Now;
            DataSfarsit = DateTime.Now;
        }

        void buttonGenereaza_Click(object sender, RoutedEventArgs e)
        {
            var totaluriChitante = FarmacieDALManager.EntitiesContext.CalculeazaTotaluriChitante(DataInceput, DataSfarsit).ToList();

            if (totaluriChitante.Count > 0)
            {
                TotaluriChitante = totaluriChitante;
                reportViewer.Visibility = Visibility.Visible;
            }
            else
            {
                reportViewer.Visibility = Visibility.Hidden;
            }
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }
}
